package com.woniu.spring.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @program: JavaEE-EFD
 * @description: 日志切点类
 * @author: fengjd
 * @create: 2022-07-28 18:55
 **/
public class LoggerAdvice {

    private static final Logger LOG = LoggerFactory.getLogger(LoggerAdvice.class);

    public void before(){
        System.out.println("在方法执行之前执行");
    }

    public void after(){
        System.out.println("在方法执行之后执行");
    }

    public void around(ProceedingJoinPoint joinPoint) {
        try {
            Object[] args = joinPoint.getArgs();// 获取实际的参数
            Object target = joinPoint.getTarget(); // 得到目标对象
            Signature signature = joinPoint.getSignature(); //获取方法签名
            Object arg = joinPoint.getArgs()[0]; // 获取第一个参数
            Object proceed = joinPoint.proceed(); //  获取切点执行结果 return结果
            LOG.error("支付了:{} 结果为:{}", arg, proceed);
        } catch (Throwable e) {
            e.printStackTrace();
            LOG.error("切点切入<支付方法>失败");
        }
    }
}
